{% extends "base.html" %}

{% block HEAD %}
<script type="text/javascript">
function show(x) { x.style.visibility="visible"; }
function hide(x) { x.style.visibility="hidden";}

function toggle_vis()
{
var x = document.getElementById("id_action-action")
var y = document.getElementById("move-div")
var z = document.getElementById("delete-div")
var a = document.getElementById("action_submit")
var b = document.getElementById("imsure")
if (x.selectedIndex == 0) {
	show(y);
	hide(z);
	a.disabled = false;
} else {
	show(z);
	a.disabled = true;
	b.checked = false;
	hide(y);
}
}

function doublecheck()
{
	var a = document.getElementById("action_submit")
	var b = document.getElementById("imsure")
	if (b.checked == true)
	{
		a.disabled = false;
	}
	else 
	{
		a.disabled = true;
	}
	
}


function checkall()
{
	var x = document.getElementById("selectall")
	var check = true;
	if (x.checked == false)
		check = false;
	for (var i = 0; i < document.getElementsByTagName('input').length; i++) {
		var e = document.getElementsByTagName('input')[i];
		if (e.type == 'checkbox') {e.checked = check;}}
}

</script>
{% endblock %}

{% block content_header %}
Search Results
{% endblock %}

{% block content %}

<p> Found {{ items_formset.total_form_count }} result{{ items_formset.total_form_count|pluralize}}</p>
<form method="post" action="/action/">{% csrf_token %}
	{{ items_formset.management_form }}
	<table width="90%" border="1">
		<tr>
			<td width="3%"><input type="checkbox" id="selectall" onclick="checkall()" /></td>
			<td width="30%">Name</td>
			<td width="10%">CAS #</td>
			<td width="10%">Molecular Formula</td>
	 		<td width="10%">Size</td>
			<td width="27%">Location</td>
			<td width="10%">Classification</td>
		</tr>
	        {% for form in items_formset %}
		<tr>
			<td>{{ form.action }}{{ form.item_id }}</td>
			<td><a href="/edit/{{ form.get_item.id }}">{{ form.get_item.name }}</a></td>
			<td>{{ form.get_item.cas_num }}</td>
			<td>{{ form.get_item.mol_formula }}</td>
			<td>{{ form.get_item.quantity }}</td>
			<td>{{ form.get_item.location }}</td>
			<td>
				{% if form.get_item.classification %}
				{{ form.get_item.classification }}
				{% else %}
				_
				{% endif %}
				</td>
		</tr>
	        {% endfor %}
	</table>
	<p>
	Selected Items:<br>
	{{ action_form.action }}
	<span id="delete-div" style="visibility:hidden"> <input type="checkbox" id="imsure" onclick="doublecheck()"/>I'm sure I want to delete the selected items</span>
	<span id="move-div"> {{ action_form.move_to }}</span> 

	<input type="submit" id="action_submit" value="do it">
	</p>
</form>

{% endblock %}